package com.heaven.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.heaven.mapper.UserMapper;
import com.heaven.pojo.PageBean;
import com.heaven.pojo.User;
import com.heaven.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public PageBean page(Integer page, Integer pageSize, String name) {
        PageHelper.startPage(page,pageSize);

        //2. 执行查询
        List<User> userList = userMapper.list(name);
        Page<User> p = (Page<User>) userList;

        //3. 封装PageBean对象
        return new PageBean(p.getTotal(), p.getResult());
    }

    @Override
    public void delete(Integer id) {
        userMapper.deleteById(id);
    }

    @Override
    public void add__re(User user) {
       userMapper.add(user);
    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }

    @Override
    public User Login(User user) {
        return userMapper.getByUsernameAndPassword(user);
    }

    @Override
    public void updatePassword(User e) {
        userMapper.updatePassword(e);
    }


}
